package 题目集.dfs.博弈论;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.BitSet;
import java.util.StringTokenizer;

public class LOL {
    static char[] lol = {'L', 'O', 'L'};
    static BitSet bitSet = new BitSet();
    static int[] nexts; //可以走的位置有哪些
    static int size;
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n=sc.nextInt();
        for (int i = 0; i < n; i++) {
            String line = sc.nextLine();
            char[] chars = line.toCharArray();
            nexts = new int[chars.length];
            size = 0;
            bitSet.clear();
            for (int j = 0; j < chars.length; j++) {
                if (chars[j] == '*') {
                    nexts[size++] = j;
                }
            }
            int res = first(chars,0);
            System.out.println(res);
        }
    }

    /**
     * -1表示先手输，1表示先手赢，0表示平局
     * @param chars
     * @return
     */
    public static int first(char[] chars,int cnt) {
        if (cnt==size) return 0;    //平局
        for (int i = 0; i < size; i++) {
            int next = nexts[i];
            if (bitSet.get(next)) continue;
            if (win(chars, next)) {    //直接赢
                return 1;
            }
            bitSet.set(next);
            for (int j = 1; j < lol.length; j++) {
                chars[next]=lol[j];
                if (first(chars,cnt+1) == -1) {    //对方必输
                    chars[next]='*';
                    bitSet.clear(next);
                    return 1;
                }
            }
            chars[next]='*';
            bitSet.clear(next);
        }
        for (int i = 0; i < size; i++) {
            int next = nexts[i];
            if (bitSet.get(next)) continue;
            bitSet.set(next);
            for (int j = 1; j < lol.length; j++) {
                chars[next]=lol[j];
                if (first(chars,cnt+1) == 0) {    //尝试追平
                    chars[next]='*';
                    bitSet.clear(next);
                    return 0;
                }
            }
            chars[next]='*';
            bitSet.clear(next);
        }
        return -1;
    }

    public static boolean win(char[] chars, int i) {
        if (i == chars.length) return false;
        if (i + 2 < chars.length && chars[i + 1] == lol[1] && chars[i + 2] == lol[2]) {
            return true;
        }
        if (i + 1 < chars.length && i - 1 >= 0 && chars[i - 1] == lol[0] && chars[i + 1] == lol[2]) {
            return true;
        }
        if (i - 2 >= 0 && chars[i - 2] == lol[0] && chars[i - 1] == lol[1]) {
            return true;
        }
        return false;
    }

    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
